/*
 * Copyright (c) "Neo4j"
 * Neo4j Sweden AB [http://neo4j.com]
 *
 * This file is part of Neo4j.
 *
 * Neo4j is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
package org.neo4j.gds.ml.core.batch;

import org.junit.jupiter.api.Test;
import org.neo4j.gds.collections.ha.HugeLongArray;
import org.neo4j.gds.core.utils.paged.ReadOnlyHugeLongArray;

import static org.assertj.core.api.Assertions.assertThat;
import static org.neo4j.gds.ml.core.batch.PrimitiveIteratorTestUtil.iteratorToArray;

class ArraySourcedBatchQueueTest {

    @Test
    void test() {
        HugeLongArray data = HugeLongArray.of(3, 6, 2, 3, 6, 2, 76, 3, 2, 6, 7, 42, 43);
        var hugeBatchQueue = new ArraySourcedBatchQueue(ReadOnlyHugeLongArray.of(data), 5);
        var b1 = hugeBatchQueue.pop();
        assertThat(b1).isPresent();
        assertThat(iteratorToArray(b1.get().elementIds())).containsExactly(3L, 6L, 2L, 3L, 6L);
        var b2 = hugeBatchQueue.pop();
        assertThat(b2).isPresent();
        assertThat(iteratorToArray(b2.get().elementIds())).containsExactly(2L, 76L, 3L, 2L, 6L);
        var b3 = hugeBatchQueue.pop();
        assertThat(b3).isPresent();
        assertThat(iteratorToArray(b3.get().elementIds())).containsExactly(7L, 42L, 43L);
    }
}
